package com.cdzx.quartz.listener;

import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
@Slf4j
public class CustomJobListener implements JobListener {
    @Override
    public String getName() {
        return "hello";
    }

    @Override
    public void jobToBeExecuted(JobExecutionContext context) {
        log.info("将要执行的任务是：{}",context.getJobDetail().getKey().getName());
    }
    @Override
    public void jobExecutionVetoed(JobExecutionContext context) {
    }
    @Override
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException e) {
        log.info("任务{}已经被执行,执行是否出错:{}",context.getJobDetail().getKey().getName(), Objects.isNull(e)?"否":"是");
    }
}
